package com.lianke.app.phpsharer.category;

import java.util.HashMap;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.lianke.app.phpsharer.R;
import com.tianxia.lib.baseworld.activity.AdapterActivity;
import com.tianxia.lib.baseworld.activity.AdapterActivity.Adapter;
import com.tianxia.lib.baseworld.main.MainTabFrame;

public class CategoryTabActivity extends AdapterActivity<Map<String, String>> {

	private int mImageHeight = 0;
    private int mDividerHeight;
    
    private TextView mItemTextView = null;
    private TextView mItemDescribeTextView = null;
	private ImageView mItemImageView = null;
	
	private String[] categorys = {"jquery", "mysql", "other", "php", "seo","wordpress","xinqingriji","woxihuan"};
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //初始化数据
        setListData();
    }
	
	/**
     * 装载列表数据
     * @param isUpdate false=初始化,true=网络获取数据后更新列表数据
     */
    private void setListData(){

        listData.clear();
        Map<String,String> map = new HashMap<String, String>(); 
        //System.out.println("R.drawable.category_icon_food->"+R.drawable.category_icon_food);
        //System.out.println("String.valueOf(R.drawable.category_icon_food)->"+String.valueOf(R.drawable.category_icon_food));
        map.put("image", String.valueOf(R.drawable.category_icon_jquery));
        map.put("name", "Jquery");
        map.put("describe", "收集jquery常用插件,弹出框、图片轮转等效果");
        listData.add(map);

        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_mysql));
        map.put("name", "mysql");
        map.put("describe", "mysql常用命令,查询工具,sql语句");
        listData.add(map);

        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_other));
        map.put("name", "other");
        map.put("describe", "提供互联网其他的资料,Android原创文章,实用小工具等");
        listData.add(map);

        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_php));
        map.put("name", "PHP");
        map.put("describe", "提供免费的php代码,全部是工作中遇到的资料,提供源代码");
        listData.add(map);

        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_seo));
        map.put("name", "seo");
        map.put("describe", "seo学习交流,seo网络优化,关键词,长尾词");
        listData.add(map);
        
        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_wordpress));
        map.put("name", "wordpress");
        map.put("describe", "提供wordpress的免费教程,学习搭建程序,wordpress优化");
        listData.add(map);
        
        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_xinqingriji));
        map.put("name", "心情日记");
        map.put("describe", "记录自己的心情日记,茶米油盐,还有酸甜苦辣..");
        listData.add(map);
        
        map = new HashMap<String, String>();
        map.put("image", String.valueOf(R.drawable.category_icon_woxihuan));
        map.put("name", "我喜欢的…");
        map.put("describe", "陈列出我所有喜欢的音乐,工作的同时来点音乐吧");
        listData.add(map);

        adapter = new Adapter(this);
        listView.setAdapter(adapter);
    }
	
	@Override
	protected void setLayoutView() {
		// TODO Auto-generated method stub
		setContentView(R.layout.category_tab_activity);
		setListView(R.id.category_tab_list);
	}

	@Override
	protected View getView(int position, View convertView) {
		//获取子项间分隔符占用的高度
		mDividerHeight = ((ListView) getListView()).getDividerHeight();
        View view = convertView;
		if (view == null) {
            view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.category_tab_list_item, null);
        }
		
		//左边的图片
        mItemImageView = (ImageView) view.findViewById(R.id.item_image);
        mItemImageView.setImageResource(Integer.parseInt(listData.get(position).get("image")));
        /*if(MainTabFrame.mainTabContainerHeight != 0){
            if(mImageHeight==0){
                mImageHeight = MainTabFrame.mainTabContainerHeight/5 - mItemImageView.getPaddingTop() - mItemImageView.getPaddingBottom() - mDividerHeight*2;
            }
            mItemImageView.getLayoutParams().height = mImageHeight;
        }*/
        //标题
        mItemTextView = (TextView) view.findViewById(R.id.item_text);
        mItemTextView.setText(listData.get(position).get("name"));

        //详细描述
        mItemDescribeTextView = (TextView) view.findViewById(R.id.item_text_describe);
        mItemDescribeTextView.setText(listData.get(position).get("describe"));

        return view;
	}

	@Override
	protected void onItemClick(AdapterView<?> adapterView, View view,
			int position, long id) {
		Intent intent = new Intent(this, CategoryListActivity.class);
        intent.putExtra("category", categorys[position]);
        intent.putExtra("title", listData.get(position).get("name"));
        startActivity(intent);

	}

}
